/**
 * Dear programmer:
 * When I wrote this code, only god and I knew how it worked.
 * Now, only god knows it!
 *
 * @author: lyl  Date: 2019-03-01 Time: 16:14
 *
 * 工程管理
 */

import React, {Component} from 'react';
import {
  SafeAreaView,
  View,
  Text,
  Image,
  TouchableOpacity,
  ScrollView,
  Modal
} from 'react-native';
import {connect} from 'react-redux';
import {styles} from './EngineerManagementScreen.Style'
import ImageAndTextCellView from "../../../../component/ImageAndTextCellView/ImageAndTextCellView"
import DividingLineViewComponent from "../../../../component/DividingLineViewComponent/DividingLineViewComponent"
import {FetchStatus} from "../../../../configuration/RequestConfiguration";
import {ReturnStatus} from "../../../../configuration/ReturnStatus";
import {doDisplayWarnMessage} from "../../../../component/Message/Action";
import {QmsRecordSummary} from "../../JobScreen/Actions";

class EngineerManagementScreen extends Component {

  static navigationOptions = () => ({
    headerTitle: `工程管理`,
  });

  // 构造
  constructor(props) {
    super(props);
    // 初始状态
    this.state = {
      modalVisible: false,
      RecordSummary:{},
    };
  }

  componentWillReceiveProps(nextProps, nextContext): void {
      let {dispatch} = this.props;
      if (nextProps.onGetRecordSummary !== this.props.onGetRecordSummary && nextProps.onGetRecordSummary.fetchStatus === FetchStatus.Success) {
          if (nextProps.onGetRecordSummary.RETURN === ReturnStatus.Success) {
              let RecordSummary = nextProps.onGetRecordSummary;
              this.setState({
                  RecordSummary: RecordSummary,
              });
              console.log(RecordSummary)
          } else {
              dispatch(doDisplayWarnMessage(nextProps.onGetRecordSummary.MSG))
          }
      }
  }

  // 组件渲染后调用
  componentDidMount() {
      // this.props.navigation.navigate('MainNavigator');
      let {dispatch} = this.props;
      let str = {};
      dispatch(QmsRecordSummary(JSON.stringify(str)))
  }

  render() {
    return (
      <SafeAreaView style={styles.body}>

        <ScrollView style={styles.body}>

          <View style={styles.headerContainer}>
            <Text style={styles.headerText}>
              关注
            </Text>
          </View>

          <TouchableOpacity activeOpacity={0.8} onPress={() => {
              this.props.navigation.navigate('InstantMaintenanceOrderScreen')
          }}>
            <ImageAndTextCellView title={'即时维修单'} num={this.state.RecordSummary.unComplate}/>
          </TouchableOpacity>

          <DividingLineViewComponent lineHeight={1}/>

          <TouchableOpacity activeOpacity={0.8} onPress={() => {
              this.props.navigation.navigate('UndispatchedEngineeringBillScreen')
          }}>
            <ImageAndTextCellView title={'未派工程单'} num={this.state.RecordSummary.unDispatch}/>
          </TouchableOpacity>

          <DividingLineViewComponent lineHeight={1}/>

        <TouchableOpacity activeOpacity={0.8} onPress={() => {
            this.props.navigation.navigate('ImmediateOrderScreen',{"status":"待复核",})
        }}>
        <ImageAndTextCellView title={'待复核工单'} num={this.state.RecordSummary.unSecondReview}/>
        </TouchableOpacity>

        <DividingLineViewComponent lineHeight={1}/>

          <View style={styles.headerContainer}>
            <Text style={styles.headerText}>
              人员
            </Text>
          </View>

          <TouchableOpacity activeOpacity={0.8} onPress={() => {
            this.props.navigation.navigate('PersonnelStatusScreen')
          }}>
            <ImageAndTextCellView title={'人员状态'}/>
          </TouchableOpacity>

          <View style={styles.headerContainer}>
            <Text style={styles.headerText}>
              设置
            </Text>
          </View>

          <TouchableOpacity activeOpacity={0.8} onPress={() => {
            this.props.navigation.navigate('QmsMaterialScreen')
          }}>
            <ImageAndTextCellView title={'耗材设置'}/>
          </TouchableOpacity>

          {/*<View style={styles.headerContainer}>*/}
            {/*<Text style={styles.headerText}>*/}
              {/*其它*/}
            {/*</Text>*/}
          {/*</View>*/}

            {/*<TouchableOpacity activeOpacity={0.8} onPress={() => {*/}
                {/*this.props.navigation.navigate('')*/}
            {/*}}>*/}
                {/*<ImageAndTextCellView title={'定期工单'}/>*/}
            {/*</TouchableOpacity>*/}

        </ScrollView>
      </SafeAreaView>
    )
  }
}

const props = state => {
  return {
      onGetRecordSummary: state.onGetRecordSummary,
  };
}

export default EngineerManagementScreen = connect(props)(EngineerManagementScreen);